package com.mercator.client.graph;

import com.mercator.client.graph.GenType.Type;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class GeneConverter {
	public static <N extends Node<GenType,N>> Collection<GenClique> convert(Collection<N> col){
		HashMap<Gene,Set<N>> gmap = new HashMap<Gene,Set<N>>();
		HashSet<GeneSet> gset = new HashSet<GeneSet>();
		TreeSet<GenClique> pset = new TreeSet<GenClique>();
		for(N n: col){
			if (n.element.type == Type.GENE && !gmap.containsValue(n.adjacentNodes)){
				for(N v : n)
					gset.add((GeneSet)v.element);
				if(!gset.isEmpty())
					pset.add(new GenClique(gset));	
				gset.clear();
				gmap.put((Gene)n.element, n.adjacentNodes);
			}
		}
		System.out.println(pset);
		return pset;
	}
}